package com.ss.android.article.base.feature.detail2.article.b;

import android.content.Context;
import android.webkit.WebView;
import com.bytedance.common.utility.Logger;
import com.bytedance.frameworks.base.mvp.Interactor;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.detail2.article.a.NewDetailViewHolder;
import com.ss.android.article.base.feature.detail2.article.c.NewDetailView;
import com.ss.android.article.base.feature.detail2.c.NewArticleDetailTTAndroidObject;
import com.ss.android.article.base.feature.detail2.d.NewDetailContext;
import org.json.JSONException;
import org.json.JSONObject;

public class WebActionInteractor extends Interactor<NewDetailView> implements NewArticleDetailTTAndroidObject.WebActionListener {
    private static final String TAG = WebActionInteractor.class.getName();
    private AppData mAppData;
    private NewDetailContext mNewDetailContext;
    private NewDetailViewHolder mNewDetailViewHolder;

    public WebActionInteractor(Context context,
                               NewDetailContext newDetailContext,
                               NewDetailViewHolder newDetailViewHolder) {
        super(context);
        this.mNewDetailContext = newDetailContext;
        this.mNewDetailViewHolder = newDetailViewHolder;
        this.mAppData = AppData.getInstance();
    }

    public final void webviewContentResize(int newheight) {
        if(newheight >= 0 && (this.mAppData.aq()) && (this.hasView())) {
            this.getView().webviewContentResize(newheight);
        }
    }

    public final void onDomReady(WebView webView) {
        JSONObject jsonObject = null;
        if(Logger.debug()) {
            Logger.d(TAG, "onDomReady");
        }

        if(webView != null && this.mNewDetailContext.article != null && this.mNewDetailViewHolder != null) {
            try {
                jsonObject = new JSONObject();
                jsonObject.put("article_type", this.mNewDetailContext.article.articleType);
                if (!android.support.design.a.isTextEmpty(this.mNewDetailContext.logExtra)) {
                    jsonObject.put("log_extra", this.mNewDetailContext.logExtra);
                }
            }
            catch(JSONException jsonException) {

            }
            if(this.mNewDetailViewHolder != null && (this.mNewDetailContext.article.hasArticleUrl())) {
                this.mNewDetailViewHolder.mWapStatHelper.onDomReady(webView, this.mNewDetailContext.article, this.mNewDetailContext.adId, jsonObject);
            }

            if(!this.hasView()) {
                return;
            }

            this.getView().hideProgressBar();
        }
    }

    public final void playNativeVideo(String vid, int arg9, int arg10, int arg11, int status, String arg13) {
        if(this.hasView()) {
            this.getView().playNativeVideo(vid, arg9, arg10, arg11, status, arg13);
        }
    }

    public final void playVideo(String arg2, int arg3, int arg4, String arg5) {
        if(this.hasView()) {
            this.getView().playVideo(arg2, arg3, arg4, arg5);
        }
    }

    public final void comment(String userName, String text, long commentId, int arg12) {
        if(this.hasView()) {
            this.getView().comment(userName, text, commentId, arg12);
        }
    }

    public final void onGetSeriesLinkPosition(int arg2) {
        if(this.hasView()) {
            this.getView().onGetSeriesLinkPosition(arg2);
        }
    }

    public final void showTitleBarPgcLayout(boolean arg2) {
        if(this.hasView()) {
            this.getView().showTitleBarPgcLayout(arg2);
        }
    }
}

